package assignment1;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class DrawShape extends JPanel
{    /*This class will make the shapes appear on the screen when the user
     chooses a JMenuItem. It will use integers to define the size of the
     shape and which shape should be drawn. I have used inheritance for this
     class as I used Polymophism for the MyShape class. This shows that I can
     use both methods.*/
    
     static public int shapeNum;
     /*This int is changed to 1, 2 or 3 depending on which JMenuItem is chosen.
      this then tells the program which shape to draw using the if statment
      defined below.*/
     
     static public int shapeSize = 50;
     /*This int defines the size of the shape, it initailises at 50 as that
      is the starting value of the JSlider in the MyContolPanel. The 
      MyControlPanel class changes the value to match the slider value. This
      means that the shapes change size as the slider is moved.*/
               
     @Override//I will override the paintComponent method to draw the shapes.
     public void paintComponent(Graphics g)
     {   super.paintComponent(g); //Call to the superclass.
         
         /*Use the Graphics2D method to set the colour and size of the lines 
           used when drawing.*/
         Graphics2D g2 = (Graphics2D)g;
         g2.setColor(Color.BLACK);
         BasicStroke pen = new BasicStroke(4F) ;
         g2.setStroke(pen);
         
         //using the shapeNum value to decide what shape is drawn.
         if(shapeNum == 1)
         {      // draw a square, uses shapeSize to define the length of sides
                Rectangle rect = new Rectangle(140,50,shapeSize*2,shapeSize*2);
                g2.draw(rect);
                }
         
         //using the shapeNum value to decide what shape is drawn.
         if(shapeNum == 2)
         {      // draw a circle, uses shapeSize to define the length of circle
                Ellipse2D.Float circle = new Ellipse2D.Float(140,50,shapeSize*2,shapeSize*2);
                g2.draw(circle);
         }
         
         //using the shapeNum value to decide what shape is drawn.
         if(shapeNum == 3)
         {     // draw a triangle, uses shapeSize to define the length of sides
               // Make a triangle, by add three points and drawing lines between them.
               Polygon poly = new Polygon();
               poly.addPoint(100, 100);
               poly.addPoint(100, shapeSize+100);
               poly.addPoint(shapeSize+100, 100);
               g2.draw(poly);
         }
     }
 }
